﻿using System;
using FluentNHibernate.Cfg;
using FluentNHibernate.Cfg.Db;

namespace Caramel.NHibernate.Membership.Mapping
{
	public static class FluentConfigurationExtensions
	{
		public static FluentConfiguration ConfigureMembership(this FluentConfiguration configuration)
		{
			return
				configuration.
					ConfigureMembership(
						MsSqlConfiguration.
							MsSql2000.
							ConnectionString(c => c.FromConnectionStringWithKey("LocalSqlServer"))
					);
		}

		public static FluentConfiguration ConfigureMembership(this FluentConfiguration configuration, IPersistenceConfigurer persistenceConfigurer)
		{
			configuration.
				Database(
					persistenceConfigurer
				).
				Mappings(
					m =>
					{
						m.
							FluentMappings.
								AddFromAssemblyOf<aspnet_ApplicationsMapping>();
					}
				).
				BuildConfiguration();

			return configuration;
		}
	}
}
